package com.example.svntest;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.RelativeLayout;

public class MainActivity extends ActivityGroup {
	
	RelativeLayout container;
	Button button1, button2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        System.out.println("DEBUG " + BuildConfig.DEBUG);
        System.out.println("button1 " + button1);
        findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				changeContainer(Activity1.class);
			}
		});
        findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				changeContainer(Activity2.class);
			}
		});
        findViewById(R.id.button3).setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				changeContainer(Activity3.class);
			}
		});
        container = (RelativeLayout)findViewById(R.id.container);
        changeContainer(Activity1.class);
    }
    
    private void changeContainer(Class<? extends Activity> clazz) {
    	Intent intent = new Intent(this, clazz);
    	intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    	Window window = getLocalActivityManager().startActivity(clazz.getName(), intent);
    	container.removeAllViews();
    	container.addView(window.getDecorView());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    
}
